package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.CarInfo;
import com.ruoyi.base.service.ICarInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Controller
 *
 * @author h w
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/base/car")
public class CarInfoController extends BaseController
{
    @Autowired
    private ICarInfoService carInfoService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('base:car:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarInfo carInfo)
    {
        startPage();
        List<CarInfo> list = carInfoService.selectCarInfoList(carInfo);
        return getDataTable(list);
    }

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('base:car:listAll')")
    @GetMapping("/listAll")
    public List listAll(CarInfo carInfo)
    {
        return carInfoService.selectCarInfoList(carInfo);
    }

    /**
     * 导出列表
     */
    @PreAuthorize("@ss.hasPermi('base:car:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarInfo carInfo)
    {
        List<CarInfo> list = carInfoService.selectCarInfoList(carInfo);
        ExcelUtil<CarInfo> util = new ExcelUtil<CarInfo>(CarInfo.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:car:query')")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Long carId)
    {
        return success(carInfoService.selectCarInfoByCarId(carId));
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:car:query')")
    @GetMapping(value = "/getInfoByCarHeadNum")
    public AjaxResult getInfoByCarHeadNum(@RequestParam String carHeadNum)
    {
        return success(carInfoService.selectCarInfoByCarHeadNum(carHeadNum));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('base:car:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarInfo carInfo)
    {
        return toAjax(carInfoService.insertCarInfo(carInfo));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('base:car:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarInfo carInfo)
    {
        return toAjax(carInfoService.updateCarInfo(carInfo));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('base:car:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carIds}")
    public AjaxResult remove(@PathVariable Long[] carIds)
    {
        return toAjax(carInfoService.deleteCarInfoByCarIds(carIds));
    }
}
